package com.catt.orderdinner.service.impl;

import com.catt.orderdinner.common.KeyUtils;
import com.catt.orderdinner.dataobject.TbUser;
import com.catt.orderdinner.repository.TbUserRepository;
import com.catt.orderdinner.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private TbUserRepository tbUserRepository;

    @Override
    public TbUser login(String username){
        // 用明文存
        TbUser tbUserByUserName = tbUserRepository.findTbUserByUserName(username);
        return tbUserByUserName;
    }

    @Override
    public TbUser login(String username, String passWord){
        // 用明文存
        return tbUserRepository.findTbUserByUserNameAndUserPassword(username,passWord);
    }

    @Override
    public void save(TbUser user){
        tbUserRepository.save(user);
    }

    @Override
    public void del(String id) {
        tbUserRepository.deleteById(id);
    }

    @Override
    public List<TbUser> findAll() {
        return tbUserRepository.findAll();
    }

    @Override
    public Page<TbUser> findAll(Pageable pageable) {
        return tbUserRepository.findAll(pageable);
    }

    @Override
    public TbUser findOneByUserId(String id) {
        return tbUserRepository.findByUserId(id);
    }
}
